﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.quest.Display.TaskFooters {
    import flash.events.*;
    import flash.display.*;
    import Events.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Display.MarketUI.*;
    import flash.text.*;
    import Modules.quest.Display.*;
    import Display.aswingui.*;

    public class PlaceNowFromInventory implements ITaskFooter {

        private static const ACTION_EVENT_PRIORITY:int = 1;
        private static const CLEANUP_EVENT_PRIORITY:int = 0;

        private var m_type:String;
        private var m_dialogView:GenericDialogView;
        private var m_inventoryList:Component;

        public function PlaceNowFromInventory(_arg1:String, _arg2:GenericDialogView){
            this.m_type = _arg1;
            this.m_dialogView = _arg2;
            this.m_dialogView.addEventListener(MarketEvent.MARKET_BUY, UI.onMarketClick, false, ACTION_EVENT_PRIORITY, true);
        }
        public function getComponent():Component{
            var _local1:Component;
            if (Global.player.inventory.getItemCountByName(this.m_type) > 0){
                _local1 = this.getFooterComponent();
                this.m_dialogView.addEventListener(Event.CLOSE, this.onClose, false, CLEANUP_EVENT_PRIORITY);
            };
            return (_local1);
        }
        private function getFooterComponent():Component{
            var _local1:Container;
            var _local2:Class = (this.m_dialogView.assetDict["subQuestField"] as Class);
            var _local3:DisplayObject = (new (_local2)() as DisplayObject);
            var _local4:Container = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.TOP);
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            _local5.setPreferredHeight(60);
            _local1 = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.RIGHT);
            var _local6:Item = Global.gameSettings.getItemByName(this.m_type);
            var _local7:int = Math.round((_local3.width * 0.6));
            var _local8:Component = ASwingHelper.makeMultilineText(ZLoc.t("Quest", "quest_place_item_now", {itemName:_local6.localizedName}), _local7, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.RIGHT, 18, 489375);
            this.m_inventoryList = new MarketCellCustomText(ZLoc.t("Dialogs", "Place"));
            (this.m_inventoryList as MarketCell).setCellValue(_local6);
            this.m_inventoryList.addEventListener(DataItemEvent.MARKET_BUY, this.onContainerClick, false, ACTION_EVENT_PRIORITY);
            _local5.append(ASwingHelper.verticalStrut(20));
            _local5.append(_local8);
            var _local9:Class = (this.m_dialogView.assetDict["placeNowArrow"] as Class);
            var _local10:DisplayObject = (new (_local9)() as DisplayObject);
            var _local11:Container = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.CENTER);
            var _local12:Component = new AssetPane(_local10);
            _local11.append(_local12);
            _local11.append(ASwingHelper.verticalStrut(5));
            _local4.append(ASwingHelper.verticalStrut(15));
            _local4.append(_local5);
            _local1.append(_local4);
            _local1.append(this.m_inventoryList);
            _local1.append(ASwingHelper.horizontalStrut(5));
            _local1.append(_local11);
            _local1.append(ASwingHelper.horizontalStrut(30));
            return (_local1);
        }
        private function onContainerClick(_arg1:DataItemEvent):void{
            this.m_dialogView.countDialogViewAction("PLACE");
            var _local2:Item = _arg1.item;
            this.placeItem(_local2);
            this.m_dialogView.close();
            this.removeListeners();
        }
        private function onButtonClick(_arg1:Event):void{
            this.placeItem(Global.gameSettings.getItemByName(this.m_type));
            this.removeListeners();
        }
        private function onClose(_arg1:Event):void{
            this.removeListeners();
        }
        private function placeItem(_arg1:Item):void{
            Sounds.playFromSet(Sounds.SET_CLICK);
            var _local2:Item = (_arg1) ? _arg1 : null;
            var _local3:MarketEvent = MarketEvent.build(MarketEvent.MARKET_BUY, _local2, MarketEvent.SOURCE_INVENTORY);
            this.m_dialogView.dispatchEvent(_local3);
        }
        private function removeListeners():void{
            if (this.m_inventoryList){
                this.m_inventoryList.removeEventListener(DataItemEvent.MARKET_BUY, this.onContainerClick);
            };
            if (this.m_dialogView){
                this.m_dialogView.removeEventListener(Event.CLOSE, this.onClose);
                this.m_dialogView.removeEventListener(MarketEvent.MARKET_BUY, UI.onMarketClick);
            };
            var _local1:QuestPopupView = (this.m_dialogView as QuestPopupView);
            if (_local1 != null){
                _local1.okayButton.removeActionListener(this.onButtonClick);
            };
        }

    }
}//package Modules.quest.Display.TaskFooters 
